<!DOCTYPE html>
<html>
	<head>
			<meta charset="utf-8" />
			<title></title>
			<button type="button" onclick="timeget()">获取当前时间get</button>
			<input type="text" name="" id="shijian" value="" /></br>
			<button type="button" onclick="gushiget()">随机获取名言get</button></br>
			<button type="button" onclick="zuozheget()">诗词作者get</button></br>
			<button type="button" onclick="shiciget()">诗词get</button></br>
			<button type="button" onclick="tianqiget()">天气get</button></br>
			<button type="button" onclick="gushipost()">随机获取名言post</button></br>
			<button type="button" onclick="zuozhepost()">诗词作者post</button><br />
			<button type="button" onclick="usergengxinpost()">用户更新post</button><br />
			<button type="button" onclick="userdenglupost()">用户登录post</button><br />
			<button type="button" onclick="userzhucepost()">用户注册post</button><br />
		</head>
		<body>
			
		</body>
		<script type="text/javascript">
			function timeget(){
				//首先先创建一个异步对象
				var time=new XMLHttpRequest();
				//用open设置请求方式（get，post）和请求地址（http：//....）
				time.open('GET','http://poetry.apiopen.top/getTime');
				//再用send去发送请求（get不需要传递参数，post需要传递参数）
				time.send();
				
				time.onreadystatechange=function(){
					//if是 判断是否交互成功 && 判断异步对象状态
					if(time.status == 200 && time.readyState == 4){
						//获取服务器响应的数据
						var obj = time.responseText;
						//解析数据
						obj=JSON.parse(obj);
						//选择其中一个放input里面
						var input=document.getElementById('shijian');
						input.value=obj.result.dateTime;
						//数据输出
						console.log(obj.result)
					}
				}
			}
			function gushiget(){
				var gushi= new XMLHttpRequest();
				gushi.open('GET','http://poetry.apiopen.top/sentences')
				gushi.send();
				gushi.onreadystatechange=function(){
					if(gushi.status == 200 && gushi.readyState == 4){
						var obj = gushi.responseText;
						obj=JSON.parse(obj);
						console.log(obj.result)
					}
				}
			}	
			function shiciget(){
				var shi = new XMLHttpRequest();
				shi.open('GET','http://poetry.apiopen.top/poetryFull?count=2&page=1');
				shi.send();
				shi.onreadystatechange = function(){
					if(shi.status == 200 &&shi.readyState == 4){
						var obj = shi.responseText;
						obj = JSON.parse(obj);
						console.log(obj.result)
					}
				}
			}
			function zuozheget(){
				var zuozhe = new XMLHttpRequest();
				zuozhe.open('GET','http://poetry.apiopen.top/poetryAuthor?count=2&page=1&name=李白');
				zuozhe.send();
				zuozhe.onreadystatechange = function(){
					if(zuozhe.status == 200 && zuozhe.readyState == 4){
						var obj = zuozhe.responseText;
						obj = JSON.parse(obj);
						console.log(obj.result)
					}
				}
			}
			function tianqiget(){
				var tianqi = new XMLHttpRequest();
				tianqi.open('GET','https://wis.qq.com/weather/common?source=xw&weather_type=forecast_1h|forecast_24h|index|alarm|limit|tips');
				tianqi.send();
				tianqi.onreadystatechange = function(){
					if(tianqi.status == 200 && tianqi.readyState == 4){
						var obj = tianqi.responseText;
						obj = JSON.parse(obj);
						console.log(obj.result)
					}
				}
			}
			function gushipost(){
				var gushi = new XMLHttpRequest();
				gushi.open('POST','http://poetry.apiopen.top/sentences');
				//gushi.setRequestHeader('Content-type','application/x-www-form-urlencoded')
				gushi.send('name=花不语，水空流。年年拚得为花愁。 & from=晏几道《鹧鸪天·守得莲开结伴游》');
				gushi.onreadystatechange = function(){
					if(gushi.status==200 &&gushi.readyState==4){
						console.log(gushi.responseText)
					}
				}
			}
			function zuozhepost(){
				var shici = new XMLHttpRequest();
				shici.open('POST','http://poetry.apiopen.top/poetryAuthor?count=2&page=1&name=李白');
				//gushi.setRequestHeader('Content-type','application/x-www-form-urlencoded')
				shici.send('name=李白 & simpleIntro=李白（701年－762年），字太白，号青莲居士，唐朝浪漫主义诗人，被后人誉为“诗仙”...');
				shici.onreadystatechange = function(){
					if(shici.status==200 &&shici.readyState==4){
						console.log(shici.responseText)
					}
				}
			}
			function usergengxinpost(){
				var gengxin = new XMLHttpRequest();
				gengxin.open('POST','https://api.apiopen.top/updateUserInfo');
				//gushi.setRequestHeader('Content-type','application/x-www-form-urlencoded')
				gengxin.send('message=peakchao & result=123456');
				gengxin.onreadystatechange = function(){
					if(gengxin.status==200 && gengxin.readyState==4){
						console.log(gengxin.responseText)
					}
				}
			}
			function userzhucepost(){
				var zhuce = new XMLHttpRequest();
				zhuce.open('POST','https://api.apiopen.top/registerUser');
				//gushi.setRequestHeader('Content-type','application/x-www-form-urlencoded')
				zhuce.send('name=peakchao & passwd=123456');
				zhuce.onreadystatechange = function(){
					if(zhuce.status==200 && zhuce.readyState==4){
						console.log(zhuce.responseText)
					}
				}
			}
		</script>
</html>
